var main = require('./main');
var app = main.server;

var mysql = require("./mysql");

//模拟用户列表
app.get("/user", function (req, resp) {
    var arr = [];
    for (var i = 0; i < 100; i++) {
        arr.push(i)
    }
    //调用mysql
    mysql.query("select * from user", function (result) {
        var userjson = JSON.stringify(result);
        resp.send(userjson);
    })
})

//模拟用户列表
app.get("/init", function (req, resp) {
    mysql.query("select * from user limit 10 ", function userList(data) {
        var users = JSON.stringify(data);
        var arr = JSON.parse(users);
        var arrName = [];
        for (var i = 0; i < arr.length; i++) {
            console.log(arr[i].name)
            arrName.push(arr[i].name)
        }
        resp.send(arrName);
    })
})


//post 测试json参数
app.post("/p", function (req, resp) {
    console.log(req.body)
    var json = {"a": "aa", "b": "bb", "c": "post"};
    resp.send(json)
})